using System;
using System.Collections.Generic;
using System.Text;

namespace Acms.AcmsControls
{
    public class PdfContentControlDisplay : BaseContentControlDisplay
    {
        private System.Web.UI.WebControls.HyperLink link;

        protected override void CreateChildControls()
        {
            link = new System.Web.UI.WebControls.HyperLink();
            this.Controls.Add(link);
            base.CreateChildControls();
        }
        private PdfContentControlProperties properties;
        protected PdfContentControlProperties Properties
        {
            get
            {
                if (properties == null)
                {
                    properties = new PdfContentControlProperties();
                }
                return properties;
            }
        }

        protected override BaseContentControlProperties GetProperties()
        {
            return Properties;
        }

        protected override void SetProperties(BaseContentControlProperties properties)
        {
            this.properties = properties as PdfContentControlProperties;
        }

        protected override void DataBindChildren()
        {
            if (Properties.HasResource())
            {
                link.NavigateUrl = string.Concat("~/File.aspx?Id=", Properties.ResourceId.ToString());
                link.ToolTip = Properties.Name;
                link.Text = Properties.Name;
                if (!string.IsNullOrEmpty(Target))
                {
                    link.Target = this.Target;
                }
            }
        }

        private string target;
        public string Target
        {
            get { return target; }
            set { target = value; }
        }

        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            EnsureChildControls();
            if (this.link == null || string.IsNullOrEmpty(this.link.NavigateUrl))
            {
                this.Visible = false;
            }
        }
    }
}
